package com.zhuiYun.project.api.dynamicState.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.zhuiYun.project.api.dynamicState.enetity.DynamicStateEntity;
import com.zhuiYun.project.api.dynamicState.mapper.DynamicStateMapper;
import com.zhuiYun.project.api.dynamicState.service.DynamicStateService;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.UploadFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName DynamicStateServiceImpl
 * @Description TODO
 * @Author mao
 * @Date 2023/4/18 9:53
 **/
@Service
public class DynamicStateServiceImpl implements DynamicStateService {
    @Autowired
    DynamicStateMapper dynamicStateMapper;

    @Autowired
    UploadFileUtils uploadFileUtils;
    /**
    * @Author mao
    * @Description 全查
    * @Date 2023/4/18 19:36
    * @Return com.zhuiYun.project.common.response.CommonResult

    */
    @Override
    public CommonResult getDynamicState(){
        List<DynamicStateEntity> dynamicStateEntities = dynamicStateMapper.selectAll();
        return CommonResult.ok(dynamicStateEntities);
    }

    @Override
    public int updateDynamicState(MultipartFile file, MultipartFile file1, MultipartFile file2, DynamicStateEntity dynamicStateEntity) {
        int i = 0;
        if (file != null){
            String s = uploadFileUtils.uploadFile(file);
            if(!StringUtils.isEmpty(s)){
                dynamicStateEntity.setLogoImg(s);
            }
        }
        if(file1 != null){
            String b = uploadFileUtils.uploadFile(file1);
            if(!StringUtils.isEmpty(b)){
                dynamicStateEntity.setWeixinQrcode(b);
            }
        }
        if(file2!=null){
            String c = uploadFileUtils.uploadFile(file2);
            if(!StringUtils.isEmpty(c)){
                dynamicStateEntity.setWeixinServe(c);
            }
        }
        if(dynamicStateEntity.getId()==null){
            i = dynamicStateMapper.insertSelective(dynamicStateEntity);
        }else{
            i= dynamicStateMapper.updateByPrimaryKeySelective(dynamicStateEntity);
        }
        return i;
    }
}
